package common.messages;

public interface KVMessage {
	
	public static final String SEPARATOR = "###";
			
	public enum StatusType {
		//client commands
		ECHO,			/* Echo - request */
		GET, 			/* Get - request */
		PUT, 			/* Put - request */
		DELETE,         /* Delete - request */
		
		//ecs commands
		UPDATE_RANGE,		/* Assign range of the memory space to be served by the server.	Used for initialization and updates of range */
		STOP_SERVER,		/* Stops the server. The server will respond with SERVER_STOPPED */		
		START_SERVER,		/* Starts the server. */
		SHUTDOWN_SERVER,	/* Shuts down the server node. All communication stops. */
		LOCK_WRITE,			/* Locks the write on a server. */
		UNLOCK_WRITE,		/* Unlocks the write on a server. */
		MOVE_DATA,			/* Moves data from a particular range to a particular server. */
		INIT_SERVER,		/*  */
		UPDATE_META,		/*  */
		
		//server responses
		ECHO_SUCCESS,	/* Echo - request successful */
		ECHO_ERROR,		/* Echo - request error */
		GET_ERROR, 		/* requested tuple (i.e. value) not found */
		GET_SUCCESS, 	/* requested tuple (i.e. value) found */
		PUT_SUCCESS, 	/* Put - request successful, tuple inserted */
		PUT_UPDATE, 	/* Put - request successful, i.e. value updated */
		PUT_ERROR, 		/* Put - request not successful */
		DELETE_SUCCESS, /* Delete - request successful */
		DELETE_ERROR,	/* Delete - request successful */ 
		LIST_KEYS_SUCCESS,   /* LIST_KEYS - request successful */
        LIST_VALUES_SUCCESS,  /* LIST_VALUES - request successful */                
        SERVER_RUNNING,         /* Server is started/resumed, all requests are processed */
    	SERVER_STOPPED,         /* Server is stopped, no requests are processed except from ECS */
    	SERVER_WRITE_LOCK,      /* Server locked for put, only get possible */
    	SERVER_WRITE_UNLOCK,      /* Server unlocked for write operatioms */
    	SERVER_NOT_RESPONSIBLE,  /* Request not successful, server not responsible for key */
        METADATA_UPDATED,		/* Metadata updated */
        DATA_MOVED,				/* Data within the specified range is moved to another server */
    	UNKNOWN					/* Unknown response */
		;	
		
		public static StatusType getStatus(String status) {
			StatusType[] statuses = StatusType.values();
			for (StatusType st: statuses) {
				if (st.name().equalsIgnoreCase(status) ) {
					return st;
				}
			}
			return UNKNOWN;
		}
	}

	/**
	 * @return the key that is associated with this message, 
	 * 		null if not key is associated.
	 */
	public String getKey();
	
	/**
	 * @return the value that is associated with this message, 
	 * 		null if not value is associated.
	 */
	public String getValue();
	
	/**
	 * @return a status string that is used to identify request types, 
	 * response types and error types associated to the message.
	 */
	public StatusType getStatus();
	
}


